<template>
  <div>
    <h2>学生信息</h2>
    <p v-if="studentInfo">{{ studentInfo.avgLoginDays }}</p>
    <p v-if="studentInfo">{{ studentInfo.avgScore}}</p>
    <p v-if="studentInfo">{{ studentInfo.avgStudyTime}}</p>
    <p v-if="studentInfo">{{ studentInfo.taskFinished}}</p>
    <!-- <p v-if="studentInfo">{{ studentInfo.value.avgLoginDays }}</p>
    <p v-if="studentInfo">{{ studentInfo.value.avgLoginDays }}</p> -->
  </div>
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios'; // Use import instead of require

const studentInfo = ref(""); // Initialize as empty string

// 发送请求获取学生信息
const studentId = 19500; // 你的学生 ID

axios.get(`http://localhost:8080/Stu/StuBasic?studentId=${studentId}`)
  .then(response => {

    console.log('StuBasic 请求成功：', response);
    // 请求成功，更新学生信息
    studentInfo.value = response.data;
    console.log(studentInfo.value);
  })
  .catch((error) => {
    // 请求失败，处理错误
    console.error("请求失败：", error);
  });

</script>
